<ui:composition template="/dynamic/layout/layout.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="content">
		<div id="welcome">
			<p style="clear: both" />
		</div>
		<h:form id="formMovies">
			<h:messages globalOnly="false" showDetail="true"
				errorClass="messagesError" fatalClass="messagesFatal"
				infoClass="messagesInfo" warnClass="messagesWarn" />
			<span>Lista filmów</span>
			<p:dataGrid var="movie" value="#{movieMBean.movies}" columns="3"
				rows="12" paginator="true"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="9,12,15">
				<p:column>
					<p:panel header="#{movie.title}" style="text-align:center">
						<h:panelGrid columns="2" style="width:100%">
							<span><b>Premiera:</b></span>
							<h:outputText value="#{movie.premiere}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
							<span><b>Opis:</b></span>
							<h:outputText
								value="#{movie.description.length() gt 40 ? movie.description.substring(0,36).concat('...') : movie.description}">
							</h:outputText>
							<p:outputPanel rendered="#{request.isUserInRole('ROLE_ADMIN')}">
								<p:commandLink title="Edytuj" action="#{movieMBean.editMovie}">
									<h:outputText styleClass="ui-icon ui-icon-search"
										style="margin:0 auto;" />
									<f:param value="#{movie.idMovie}" name="movieId" />
								</p:commandLink>
							</p:outputPanel>
							<p:outputPanel rendered="#{!request.isUserInRole('ROLE_ADMIN')}">
								<p:commandLink title="Edytuj" action="#{movieMBean.showMovie}">
									<h:outputText styleClass="ui-icon ui-icon-search"
										style="margin:0 auto;" />
									<f:param value="#{movie.idMovie}" name="movieId" />
								</p:commandLink>
							</p:outputPanel>

						</h:panelGrid>
					</p:panel>
				</p:column>
			</p:dataGrid>
		</h:form>

		<div id="main_content"></div>

	</ui:define>
</ui:composition>
